package com.heatup.apt.common.dao;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.baomidou.mybatisplus.mapper.AutoMapper;
import com.heatup.apt.model.api.ServicePriceResultModel;
import com.heatup.apt.model.api.course.CoursePriceModel;
import com.heatup.apt.model.product.ServicePrice;
import com.heatup.apt.model.product.ServicePriceExample;
import com.heatup.apt.model.user.UserDiscount;
import com.heatup.apt.model.user.UserInfo;

import org.springframework.stereotype.Component;

@Component
public interface ServicePriceMapper  extends AutoMapper<ServicePrice>{
    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table service_price
     *
     * @mbggenerated
     */
    int countByExample(ServicePriceExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table service_price
     *
     * @mbggenerated
     */
    int deleteByExample(ServicePriceExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table service_price
     *
     * @mbggenerated
     */
    @Delete({
        "delete from service_price",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table service_price
     *
     * @mbggenerated
     */
    @Insert({
        "insert into service_price (id, service_type, ",
        "service_name, store_id, ",
        "course_id, level, ",
        "prime_price, price, ",
        "duration, unit, ",
        "min_count)",
        "values (#{id,jdbcType=INTEGER}, #{serviceType,jdbcType=INTEGER}, ",
        "#{serviceName,jdbcType=VARCHAR}, #{storeId,jdbcType=INTEGER}, ",
        "#{courseId,jdbcType=INTEGER}, #{level,jdbcType=INTEGER}, ",
        "#{primePrice,jdbcType=DECIMAL}, #{price,jdbcType=DECIMAL}, ",
        "#{duration,jdbcType=INTEGER}, #{unit,jdbcType=INTEGER}, ",
        "#{minCount,jdbcType=INTEGER})"
    })
    int insert(ServicePrice record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table service_price
     *
     * @mbggenerated
     */
    int insertSelective(ServicePrice record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table service_price
     *
     * @mbggenerated
     */
    List<ServicePrice> selectByExample(ServicePriceExample example);

    // 查询课程详情用到：主要是为了查询出对应城市的折扣，及计算 
    CoursePriceModel queryCoursePriceModelByCourseId(Integer courseId);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table service_price
     *
     * @mbggenerated
     */
    @Select({
        "select",
        "id, service_type, service_name, store_id, course_id, level, prime_price, price, ",
        "duration, unit, min_count,  version",
        "from service_price",
        "where id = #{id,jdbcType=INTEGER}"
    })
    @ResultMap("BaseResultMap")
    ServicePrice selectByPrimaryKey(Integer id);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table service_price
     *
     * @mbggenerated
     */
    int updateByExampleSelective(@Param("record") ServicePrice record, @Param("example") ServicePriceExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table service_price
     *
     * @mbggenerated
     */
    int updateByExample(@Param("record") ServicePrice record, @Param("example") ServicePriceExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table service_price
     *
     * @mbggenerated
     */
    int updateByPrimaryKeySelective(ServicePrice record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table service_price
     *
     * @mbggenerated
     */
    @Update({
        "update service_price",
        "set service_type = #{serviceType,jdbcType=INTEGER},",
          "service_name = #{serviceName,jdbcType=VARCHAR},",
          "store_id = #{storeId,jdbcType=INTEGER},",
          "course_id = #{courseId,jdbcType=INTEGER},",
          "level = #{level,jdbcType=INTEGER},",
          "prime_price = #{primePrice,jdbcType=DECIMAL},",
          "price = #{price,jdbcType=DECIMAL},",
          "duration = #{duration,jdbcType=INTEGER},",
          "unit = #{unit,jdbcType=INTEGER},",
          "min_count = #{minCount,jdbcType=INTEGER}",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(ServicePrice record);
    /**
     * 修改服务版本号
     * ServicePriceMapper.updateServicePriceVersion()<BR>
     * <P>Author :  fangxiaowen </P>  
     * <P>Date : 2016年8月26日 </P>
     * @param params
     * @return
     */
    int updateServicePriceVersion(Map<Object, Object> params);
    
    
	 /**
	  * 根据类型、门店、课程ID查询价格信息
	  * serviceType,courseId,storeId   
	  */
	ServicePriceResultModel queryServicePriceByMap(Map<String, Object> params);

    /**
     * 查询课程折扣价格
     * @param courseId
     * @return
     */
    ServicePriceResultModel queryCoursePriceByCourseId(Integer courseId);

    /**
     * 根据课程ID删除课程价格关联信息
     * @param courseId
     * @return
     */
    @Delete({
            "delete from service_price",
            "where service_type =3 and course_id = #{id,jdbcType=INTEGER}"
    })
    int deleteByCourseId(Integer courseId);

    /**
     * 根据门店ID删除价格关联信息
     * @param id
     * @return
     */
    @Delete({
            "delete from service_price",
            "where service_type =4 and store_id = #{id,jdbcType=INTEGER}"
    })
    int deleteByStoreId(Integer id);

    /**
     * 根据檬营课程ID查询价格ID
     * @param id
     * @return
     */
    @Select({
            "select id from service_price",
            "where service_type =3 and course_id = #{id,jdbcType=INTEGER}"
    })
    Integer queryServicePriceByCourseId(Integer id);
    
    @Select({
        "select id from service_price",
        "where service_type =#{serviceType,jdbcType=INTEGER}"
	})
	Integer queryServicePriceByServiceType(Integer serviceType);

    /**
     * 根据门店ID查询门店价格ID
     * @param id
     * @return
     */
    @Select({
            "select id from service_price",
            "where service_type=4 and store_id = #{id,jdbcType=INTEGER}"
    })
    Integer queryServicePriceIdByStoreId(Integer id);
    /**
     * 查询会员价格
     * @param id
     * @return
     */
    @Select({
        "select id,type,date_type dateType,prime_price primePrice,recommend,discount,remarks from user_discount",
        "where id = #{id,jdbcType=INTEGER}"
	})
    UserDiscount getUserDiscountById(int id);

    List<ServicePrice> selectServicePriceBy(Map<String,Object> param);
    
    /**
     * 根据服务类别查询 产品服务 主要用于 餐 体测 体验 等 只有一条数据的查询
     * @param serviceType
     * @return
     */
    public ServicePrice queryServicePriceByServiceTypeOne(Integer serviceType);
   
}